
const path = require('path')

const webpack = require('webpack')

// "dev2": "webpack-dev-server --contentBase src --hot",
// 1.自动在内存中根据指定页面生成一个内存的页面
// 2.自动把打包好的bundle.js 追加到页面中去
const htmlWebpackPlugin = require ('html-webpack-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')

module.exports = {
    mode: "development",
    entry: path.join(__dirname, './src/main.js'),
    output: {
        path: path.join(__dirname, './dist'),
        filename: 'bundle.js'
    },
    devServer: {
        port: 3000,
        contentBase: 'src'
        // hot: true
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new VueLoaderPlugin(),
        new htmlWebpackPlugin({
            template: path.join(__dirname, './src/index.html'),
            filename: 'index.html'
        }),
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery",
            jquery: "jquery",
            "window.jQuery": "jquery"
        })
    ],
    resolve: {
        alias: {
            // "vue$": "vue/dist/vue.js"
        }
    },
    module: {
        rules: [
            {
                test: /\.css$/, 
                use: ['style-loader', 'css-loader']
            },
            {
                test: /\.less$/,
                use: ['style-loader', 'css-loader', 'less-loader']
            },
            {
                test: /\.scss$/,
                use: ['style-loader', 'css-loader', 'sass-loader']
            },
            {
                test: /\.(jpg|png|gif|bmp|jpeg)$/,
                use: [
                    {
                        loader: 'url-loader',
                        options: {
                            limit: 1024,
                            name: '[hash:8]-[name].[ext]'
                        }
                    }
                ]
            },
            {
                test: /.woff|.woff2|.svg|.eot|.ttf|otf/,
                use: [
                    {
                        loader: 'url-loader',
                        options: {
                            name: '[hash:8]-[name].[ext]'
                        }
                    }
                ]
            },
            {
                test: /\.js$/,
                use: 'babel-loader',
                exclude: /node_modules/
            },
            {
                test: /\.vue$/,
                use: 'vue-loader'
            }
        ]
    }
}